﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Core.Interface;
using PServiceBus.Core.Runtime.Transports;
using PServiceBus.RabbitMQ;
using System.Runtime.Serialization;
using System.ComponentModel.Composition;
using PServiceBus.Core.Runtime;

namespace PServiceBus.Transports {
    [Serializable]
    [DataContract]
    [Export(typeof(ITransport))]
    public class RabbitMQTransport : ITransport, IDeletableTransport {

        [DataMember]
        public string Path { get; set; }

        #region ITransport Members
        [DataMember]
        public TransportFormat Format { get; set; }

        public TransportResponse Send(string message, Dictionary<string, object> messageStructure) {
            var tranResponse = TransportResponse.New<RabbitMQTransport>();
            try {
                Provider<string>.GetProvider(Path).Add(message);
                tranResponse.Success = true;
            }
            catch (Exception ex) {
                tranResponse.Message = ex.ToString();
            }
            return tranResponse;
        }
        #endregion

        #region IDeletableTransport Members

        void IDeletableTransport.Delete() {
            Provider<string>.GetProvider(Path).Delete();
        }

        #endregion
    }
}
